<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2021/10/22
 * Time: 16:01
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

namespace app\common\business;


use app\common\validate\Money as ValObj;
use app\common\model\mysql\Money as ModelObj;
use think\Exception;
use think\facade\Log;

class Money extends Base
{
    /**
     * @var ValObj
     */
    protected ValObj $valObj;
    /**
     * @var ModelObj
     */
    protected ModelObj $modelObj;

    /**
     *
     */
    public function __construct()
    {
        $this->valObj = new ValObj();
        $this->modelObj = new ModelObj();
    }

    /**
     * @param string $openid
     * @return float
     * @throws Exception
     */
    public function getUserOpenidByMoneyCount(string $openid = '')
    {
        try {
            $money = $this->modelObj->getUserOpenidByMoneyCount($openid);
        } catch (\Exception $e) {
            throw new Exception("查询失败");
        }
        //总共可用金额
        if(!$money['money']){
            $count = 0;
        }else {
            $count = $money['money'];
        }
        //查询可提金额
        try {
            $already = (new MoneyList())->getMoneyListByCount($openid);
        } catch (\Exception $e) {
            throw new Exception($e->getMessage());
        }
        //根据学校分类查询 扣除学校的金额
//        $this->modelObj->getUserOpenidBy();
        return round($count - $already, 2);
    }
}